using UnityEngine;

public class BallState_Block : AbstractBallState
{
	public static BallState_Block instance;

	private BallState_Block()
	{
	}

	public static BallState_Block getInstance()
	{
		if (instance == null)
		{
			instance = new BallState_Block();
		}
		return instance;
	}

	public override void enter(Ball owner)
	{
		base.enter(owner);
		owner.setVelocityZero();
		owner.block_move_speed = Vector3.Distance(owner.getPosition(), owner.block_block_point) / (float)owner.block_leftframe / Time.fixedDeltaTime;
	}

	public override void fixedUpdate(Ball owner)
	{
		base.fixedUpdate(owner);
		//if (MathHelper.getSqrDistance(owner.getPosition(), owner.block_block_point) < 0.1f)
		//{
			Instance<Court>.instance.setNoOffenseTeam();
			owner.GetComponent<Rigidbody>().AddForce(owner.block_blocked_back.normalized * Random.Range(1, 6), ForceMode.Impulse);
			owner.do_rebound();
			if (owner.player_make_ball_outside.teamType == TeamType.USER)
			{
				if (Random.Range(0, 2) == 0)
				{
					Instance<AudioController>.instance.play(AudioType.Sound_audience_man);
				}
				else
				{
					Instance<AudioController>.instance.play(AudioType.Sound_audience_women);
				}
			}
			else
			{
				Instance<AudioController>.instance.play(AudioType.Sound_weak);
			}
			Instance<AudioController>.instance.play(AudioType.Sound_catch);
		//}
		//else
		//{
		//	GameHelper.MoveTo(owner.myTransform, owner.block_block_point, owner.block_move_speed);
		//}
	}
}
